﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
using System.Net;
using System.IO;
using System.Web.Script.Serialization;
using PiscoSourDominio; 

namespace PiscoSourWeb.Models
{
    public class ModelDesigner : IDisposable
    {
        public IEnumerable<Reserva> ObtenerReservasDeldia()
        {
            HttpWebRequest req2 = (HttpWebRequest)WebRequest
                    .Create("http://localhost:49781/Services/Reservas.svc/Reservas");
            req2.Method = "GET";
            HttpWebResponse res2 = (HttpWebResponse)req2.GetResponse();
            StreamReader reader2 = new StreamReader(res2.GetResponseStream());
            string ReservaJson2 = reader2.ReadToEnd();
            JavaScriptSerializer js2 = new JavaScriptSerializer();
            List<Reserva> lista = js2.Deserialize<List<Reserva>>(ReservaJson2);
            return lista;
        }

        public IEnumerable<Reserva> ObtenerReservasTotalRestaurante(string codigo)
        {
            string strdata = "/" + codigo;
            HttpWebRequest httpReq = (HttpWebRequest)WebRequest.Create("http://localhost:49781/Services/Reservas.svc/ReservasRest" + strdata);
            httpReq.Method = "POST";
            httpReq.ContentType = "application/json";

            var Resrp = (HttpWebResponse)httpReq.GetResponse();
            StreamReader strread = new StreamReader(Resrp.GetResponseStream());
            string strJson = strread.ReadToEnd();

            JavaScriptSerializer js = new JavaScriptSerializer();
            List<Reserva> objReserva = js.Deserialize<List<Reserva>>(strJson);
            return objReserva;
        }


        public IEnumerable<Reserva> ObtenerReservasCliente(string codigo)
        {
            string strdata = "/" + codigo;
            HttpWebRequest httpReq = (HttpWebRequest)WebRequest.Create("http://localhost:49781/Services/Reservas.svc/ReservasCliente" + strdata);
            httpReq.Method = "GET";
            httpReq.ContentType = "application/json";

            var Resrp = (HttpWebResponse)httpReq.GetResponse();
            StreamReader strread = new StreamReader(Resrp.GetResponseStream());
            string strJson = strread.ReadToEnd();

            JavaScriptSerializer js = new JavaScriptSerializer();
            List<Reserva> objReserva = js.Deserialize<List<Reserva>>(strJson);
            return objReserva;
        } 

        public void Dispose()
        {
            
        }
 
    }

}